#include <QRegExp>
#include <QDebug>
#include "cvactivity.h"

CVActivity::CVActivity()
{

}

void CVActivity::setKey(const QString &key)
{
    this->key = key;
}

void CVActivity::setTitle(const QString &title)
{
    this->title = title;
}

void CVActivity::setMessage(const QString &message)
{
    this->message = message;
}

void CVActivity::setSubjectIcon(const QString &subjectIcon)
{
    this->subjectIcon = subjectIcon;
}

void CVActivity::setObjectId(const QString &objectId)
{
    this->objectId = objectId;
}

void CVActivity::setObjectType(const QString &objectType)
{
    this->objectType = objectType;
}

void CVActivity::setActionType(const QString &actionType)
{
    this->actionType = actionType;
}

void CVActivity::setDescription(const QString &description)
{
    this->description = description;
}

void CVActivity::setMimeType(const QString &mimeType)
{
    this->mimeType = mimeType;
}

void CVActivity::setFileVersion(const QString &fileVersion)
{
    this->fileVersion = fileVersion;
}

void CVActivity::setIsDownloadable(bool bDownloadable)
{
    this->bDownloadable = bDownloadable;
}

void CVActivity::setObjectSmallIcon(const QString &objectSmallIcon)
{
    this->objectSmallIcon = objectSmallIcon;
}

void CVActivity::setCommentsOn(const QString &commentsOn)
{
    this->commentsOn = commentsOn;
}

void CVActivity::setCommentsCount(const QString &commentsCount)
{
    this->commentsCount = commentsCount;
}

void CVActivity::setPosted(const QString &posted)
{
    this->posted = posted;
}

void CVActivity::setTimeDiff(const QString &timeDiff)
{
    this->timeDiff = timeDiff;
}

void CVActivity::setRiverId(const QString &riverId)
{
    this->riverId = riverId;
}

void CVActivity::setRid(const QString &rid)
{
    this->rid = rid;
}

void CVActivity::setParams(QList<CVActivityParam *> params)
{
    if (params.size() > 0)
    {
        CVActivityParam *param = params.at(0);
        this->actorId = param->getGuid();
    }
    this->params = params;
}

QString CVActivity::getKey()
{
    return this->key;
}

QString CVActivity::getTitle()
{
    return this->title;
}

QString CVActivity::getMessage()
{
    return this->message;
}

QString CVActivity::getTranslateMessage()
{
    if (this->params.size() > 0)
    {
        QString title = message;
        //qDebug() << "Title: " << title;
        for(int i=0; i <params.size(); ++i)
        {
            QString placeholder = "%" + QString::number((i + 1)) + "\\$s";
            QString type = params.at(i)->getType();
            QString guid = params.at(i)->getGuid();
            QString subtype = params.at(i)->getSubtype();
            QString href = type + "/" + guid;
            if (!subtype.isEmpty())
            {
                href = type + "/" + subtype + "/" + guid;
            }
            if (type == "plaintext")
            {
                title.replace(QRegExp(placeholder), params.at(i)->getName());
            }
            else
            {
                title.replace(QRegExp(placeholder), "<a href='" + href + "'>" + params.at(i)->getName() + "</a>");
            }
        }
        return title;
    }
    else
    {
        return this->message;
    }
}

QString CVActivity::getSubjectIcon()
{
    return this->subjectIcon;
}

QString CVActivity::getObjectId()
{
    return this->objectId;
}

QString CVActivity::getObjectType()
{
    return this->objectType;
}

QString CVActivity::getActionType()
{
    return this->actionType;
}

QString CVActivity::getDescription()
{
    return CVUtil::filterString(this->description);
}

QString CVActivity::getMimeType()
{
    return this->mimeType;
}

QString CVActivity::getFileVersion()
{
    return this->fileVersion;
}

bool CVActivity::isDownloadable()
{
    return this->bDownloadable;
}

QString CVActivity::getObjectSmallIcon()
{
    return this->objectSmallIcon;
}

QString CVActivity::getCommentsOn()
{
    return this->commentsOn;
}

QString CVActivity::getCommentsCount()
{
    return this->commentsCount;
}

QString CVActivity::getPosted()
{
    return CVUtil::prettyTime(this->posted);
}

QString CVActivity::getTimeDiff()
{
    return this->timeDiff;
}

QString CVActivity::getRiverId()
{
    return this->riverId;
}

QString CVActivity::getRid()
{
    return this->rid;
}

QList<CVActivityParam *> CVActivity::getParams()
{
    return this->params;
}

QString CVActivity::getActorId()
{
    return this->actorId;
}
